package net.alche.al.util.far;

import net.alche.al.util.alches.ToolDate;
import net.alche.al.util.far.plugin.spring.SpringBCryptPasswordEncoder;
import net.alche.al.util.far.pojo.FaTimerAbs;
import net.alche.al.util.far.pojo.ResultPack;
import net.alche.al.util.far.pojo.ext.InnerTimerDo;
import net.alche.fa.core.FaClass;
import net.alche.fa.core.FaUtil;
import net.alche.fa.core.SageStone;
import net.alche.fa.core.model.FaValue;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.RuntimeUtil;
import cn.hutool.extra.mail.MailAccount;
import cn.hutool.extra.mail.MailUtil;
import cn.hutool.extra.pinyin.PinyinUtil;
import fx.web.ctrl.pojo.UpdSerProInfo;

import java.io.File;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.Map.Entry;
import java.util.regex.Pattern;

import javax.swing.Renderer;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.text.StringEscapeUtils;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;

import java.util.regex.Matcher;
import java.util.HashMap;
import java.util.LinkedList;

import net.alche.al.util.far.pojo.ExceptionPack;
import net.alche.al.util.AC;
import net.alche.al.util.Far;
import java.util.ArrayList;
import java.util.Date;

import net.alche.al.util.M;
import java.lang.management.ManagementFactory;
import com.sun.management.OperatingSystemMXBean;

// FaBaseTol
@SuppressWarnings("all")
public class FaBaseTol {
  SimpleDateFormat sdfYmdTHms = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
  // static final Logger logger = LogManager.getLogger(FaBaseTol.class);
  private static Pattern NUMBER_PATTERN = Pattern.compile("-?[0-9]+(\\.[0-9]+)?");
  public ToolDate td = new ToolDate();
  SpringBCryptPasswordEncoder bcrypt = null;
  // static ObjectMapper objectMapper = null;
  public int uniIndex = 0;
  public static final String[] imgSufs = new String[] { ".png", ".jpg", ".jpeg", ".gif", "bmp", ".PNG", ".JPG", ".JPEG",
      ".GIF", "BMP" };
  Map<Integer, FaTimerAbs> timerMap = null;
  Timer timerUtil = null;
  public String separator = File.separator;
  Map<String, String> contentTypeMap = null;
  String osType = null; // 系统类型

  // public ObjectMapper getJsonUtil() {
  // if (objectMapper == null) {
  // objectMapper = new ObjectMapper();
  // objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
  // objectMapper.setVisibility(PropertyAccessor.ALL,
  // JsonAutoDetect.Visibility.ANY);
  // objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
  // objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
  // false);
  // }
  // return objectMapper;
  // }

  public String toJsonTxt(Object obj) {
    try {
      if (obj != null && obj instanceof SageStone) {
        return Far.sageUtil.toJsonTxt((SageStone) obj);
      } else {
        return Far.gson.toJson(obj);
        // return getJsonUtil().writeValueAsString(obj);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }

  public boolean noEmpty(Object obj) {
    return !this.empty(obj);
  }

  public boolean notEmpty(Object obj) {
    return !this.empty(obj);
  }

  public boolean empty(Object obj) {
    if (obj == null) {
      return true;
    }
    if (obj instanceof List && ((List) obj).isEmpty()) {
      return true;
    }
    if (obj instanceof Map && ((Map) obj).isEmpty()) {
      return true;
    }
    if (obj instanceof String && ((String) obj).equals("")) {
      return true;
    }
    return false;
  }

  public boolean isNumber(String str) {
    // Pattern pattern = Pattern.compile("[0-9]*");
    Matcher isNum = NUMBER_PATTERN.matcher(str);
    if (!isNum.matches()) {
      return false;
    }
    return true;
  }

  public String parseStr(Object obj) {
    if (obj == null) {
      return "";
    }
    return String.valueOf(obj);
  }

  public boolean parseBool(Object obj) {
    if (obj == null) {
      return false;
    }
    if (obj instanceof String) {
      return Boolean.parseBoolean(obj.toString());
    }
    return (Boolean) obj;
  }

  public Integer toInt(String obj) {
    if (obj == null) {
      return 0;
    }
    try {
      return Integer.parseInt(obj);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    return 0;
  }

  public Map<String, Object> pickMap(Object obj, String keys) {
    Map<String, Object> map = new HashMap<>();
    if (keys != null && obj != null) {
      String[] sp = keys.split(",");
      for (int i = 0; i < sp.length; i++) {
        Object val = Far.java.getAttr(obj, sp[i]);
        if (val != null) {
          map.put(sp[i], val);
        }
      }
    }
    return map;
  }

  public <T> T parseJson(String json, Class clas) {
    try {
      return (T) Far.gson.fromJson(json, clas);
      // return (T) getJsonUtil().readValue(json, clas);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }

  public FaValue parseJson(String json, FaClass clas) {
    return Far.java.parseJson(json, clas);
  }

  public <T> List<T> parseJsonList(String json, Class<T> clas) {
    try {
      return AC.json.getList(json, clas);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }

  public FaValue parseJsonList(String json, FaClass clas) {
    try {
      return Far.java.parseJsonList(json, clas);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }

  public String map_getStr(Map map, String key) {
    if (map == null) {
      return "";
    }
    Object val = map.get(key);
    if (val != null) {
      return Far.tl.parseStr(val);
    }
    return "";
  }

  public String double_dot2(Double val) {
    if (val == null) {
      return "0.00";
    }
    return String.format("%.2f", val);
  }

  public int string_len(String val) {
    if (val == null) {
      return 0;
    }
    return val.length();
  }

  public int list_len(List list) {
    if (list == null) {
      return 0;
    }
    return list.size();
  }

  public boolean string_eq(String val, String v2) {
    if (val == null && v2 == null) {
      return true;
    }
    if (val == null) {
      return false;
    }
    if (val.equals(v2)) {
      return true;
    }
    return false;
  }

  public boolean string_no_eq(String val, String v2) {
    return !this.string_eq(val, v2);
  }

  public boolean isImgPath(String path) {
    for (String str : imgSufs) {
      if (path.endsWith(str)) {
        return true;
      }
    }
    return false;
  }

  public boolean isJpg(String path) {
    if (path != null
        && (path.endsWith(".jpg") || path.endsWith(".jpeg") || path.endsWith(".JPG") || path.endsWith(".JPEG"))) {
      return true;
    }
    return false;
  }

  public boolean isPng(String path) {
    if (path != null && (path.endsWith(".png") || path.endsWith(".PNG"))) {
      return true;
    }
    return false;
  }

  // public <T> T fromJson(String json, Type type)
  // return Far.gson.fromJson(json, type)
  public <T> T fromJson(String json, Class cls) {
    return Far.tl.parseJson(json, cls);
  }

  public FaValue fromJson(String json, FaClass cls) {
    Map mp = Far.tl.fromJsonMap(json);
    return FaUtil.mapToPojo(cls.getPlat(), cls.getConf().getName(), mp);
  }

  public List fromJsonList(String json, Class cls) {
    return parseJsonList(json, cls);
  }

  public FaValue fromJsonList(String json, FaClass cls) {
    List<Map> list = getMapList(json);
    FaValue fav = new FaValue();
    if (list != null) {
      List toList = new ArrayList<>();
      fav.aiData(toList);
      for (Map mp : list) {
        toList.add(FaUtil.mapToPojo(cls.getPlat(), cls.getConf().getName(), mp));
      }
    }
    return fav;
  }

  public Map fromJsonMap(String json) {
    if (M.emp(json)) {
      return null;
    }
    try {
      return Far.gson.fromJson(json, HashMap.class);
      // getJsonUtil().readValue(json, Map.class);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }

  public Map<String, String> fromJsonTxtMap(String json) {
    if (M.emp(json)) {
      return null;
    }
    HashMap<String, String> bodyMpInfo = new HashMap<>();
    try {
      JsonObject jsonObj = new JsonParser().parse(json).getAsJsonObject();
      Map<String, JsonElement> jsonMap = jsonObj.asMap();
      for (Entry<String, JsonElement> node : jsonMap.entrySet()) {
        String val = node.getValue().toString();
        if (val.startsWith("\"") && val.endsWith("\"")) {
          val = val.substring(1, val.length() - 1);
        }
        val = StringEscapeUtils.unescapeJson(val);
        bodyMpInfo.put(node.getKey(), val);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return bodyMpInfo;
  }

  public List<Map> getMapList(String json) {
    if (M.emp(json)) {
      return null;
    }
    try {
      return Far.gson.fromJson(json, new TypeToken<List<HashMap>>() {
      }.getType());
      // return getJsonUtil().readValue(json, List.class);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }

  // public void copyTxt(Context context, String txt)
  // ClipboardManager cmb =
  // (ClipboardManager)context.getSystemService(Context.CLIPBOARD_SERVICE)
  // 创建一个剪贴数据集，包含一个普通文本数据条目（需要复制的数据）
  // ClipData clipData = ClipData.newPlainText(null, txt)
  // cmb.setPrimaryClip(clipData)
  public String dot2(Double val) {
    return M.dot2(val);
  }

  public List<Integer> transToInts(String str) {
    List<Integer> list = new ArrayList<>();
    if (M.noEmp(str)) {
      String[] sp = str.split(",");
      for (String item : sp) {
        list.add(Integer.parseInt(item));
      }
    }
    return list;
  }

  public ResultPack valiPack(String txt) {
    ResultPack rp = new ResultPack();
    rp.setState(ExceptionPack.DATA_VALIDATE);
    rp.setMsg(txt);
    return rp;
  }

  public String getPinyin(String txt) {
    if (M.emp(txt))
      return "";
    return PinyinUtil.getPinyin(txt, "");
  }

  public String getBCryptCoder(String txt) {
    if (M.emp(txt))
      return "";
    return this.getBcrypt().encode(txt);
  }

  public SpringBCryptPasswordEncoder getBcrypt() {
    if (this.bcrypt == null) {
      this.bcrypt = new SpringBCryptPasswordEncoder();
    }
    return this.bcrypt;
  }

  public boolean compareBCrypt(String str1, String str2) {
    if (AC.empty(str1) || AC.empty(str2)) {
      return false;
    }
    return getBcrypt().matches(str1, str2);
  }

  public void startTimer(String unit, int val, FaTimerAbs timeDo) {
    timeDo.uuId = this.newUniIndex();
    timeDo.timeVal = val;
    timeDo.unit = unit;
    timeDo.lastDone = new Date();
    this.getTimerMap().put(timeDo.uuId, timeDo);
  }

  public void startTimer(String unit, Integer val, SageStone timeDo) {
    if (timeDo != null) {
      FaTimerAbs ta = new FaTimerAbs();
      ta.sageVal = timeDo;
      this.startTimer(unit, val, ta);
    }
  }

  public int newUniIndex() {
    return this.uniIndex++;
  }

  public Map<Integer, FaTimerAbs> getTimerMap() {
    if (this.timerMap == null) {
      timerMap = new HashMap<>();
      this.getTimer().schedule(new InnerTimerDo(timerMap) {
      }, 5000, 5000);
    }
    return this.timerMap;
  }

  public Timer getTimer() {
    if (timerUtil == null) {
      timerUtil = new Timer();
    }
    return timerUtil;
  }

  public boolean sendMail(Map<String, Object> mp) {
    try {
      MailAccount acc = new MailAccount();
      acc.setFrom(M.s(mp, "username"));
      acc.setHost(M.s(mp, "host"));
      acc.setPort(M.i(mp, "port"));
      acc.setPass(M.s(mp, "password"));
      acc.setSslEnable(true);
      acc.setAuth(true);
      String result = MailUtil.send(acc, M.ls(mp, "toMore"), M.s(mp, "title"), M.s(mp, "content"), false);
      if (result.startsWith("<") && result.endsWith(">")) {
        return true;
      }
      // Far.log("send-mail-result", result);
    } catch (Exception ex) {
      ex.printStackTrace();
      return false;
    }
    return true;
  }

  // // 发送ali平台短信
  // public boolean sendAliSms(Map<String, Object> mp, Map<String, String> params)
  // {
  // String accessKeyId = M.s(mp, "keyId");
  // String accessKeySecret = M.s(mp, "keySecret");
  // try {
  // Client client = createClient(accessKeyId, accessKeySecret);
  // SendSmsRequest req = new SendSmsRequest();
  // List list = M.ls(mp, "numbers");
  // req.setPhoneNumbers(M.toSpStr(list, ","));
  // req.setSignName(M.s(mp, "signName"));
  // req.setTemplateCode(M.s(mp, "tempCode"));
  // req.setTemplateParam(Far.tl.toJsonTxt(params));
  // // 复制代码运行请自行打印 API 的返回值
  // SendSmsResponse response = client.sendSms(req);
  // if ("OK".equals(response.getBody().code)) {
  // return true;
  // } else {
  // logger.info("短信失败:" + Far.tl.toJsonTxt(response.getBody()));
  // }
  // } catch (Exception e) {
  // e.printStackTrace();
  // }
  // return false;
  // }

  // public Client createClient(String accessKeyId, String accessKeySecret) throws
  // Exception {
  // Config config = new Config()
  // // 您的AccessKey ID
  // .setAccessKeyId(accessKeyId)
  // // 您的AccessKey Secret
  // .setAccessKeySecret(accessKeySecret);
  // // 访问的域名
  // config.endpoint = "dysmsapi.aliyuncs.com";
  // return new com.aliyun.dysmsapi20170525.Client(config);
  // }

  // public List<Map> readExcel(String fullPath) {
  // ExcelReader reader = ExcelUtil.getReader(fullPath);
  // List<Map<String, Object>> readAll = reader.readAll();
  // return (List) readAll;
  // }

  // public boolean writeExcel(String fullPath, FaExportExcel ee) {
  // try {
  // ExcelWriter writer = ExcelUtil.getWriter(fullPath);
  // if (ee.widths != null) {
  // for (int i = 0; i < ee.widths.length; i++) {
  // writer.setColumnWidth(i, ee.widths[i]);
  // }
  // }
  // writer.writeHeadRow(Arrays.asList(ee.titles));
  // // 一次性写出内容，使用默认样式，强制输出标题
  // writer.write(ee.getColsList(), true);
  // // 关闭writer，释放内存
  // writer.close();
  // } catch (Exception ex) {
  // logger.error(ex.getMessage());
  // ex.printStackTrace();
  // return false;
  // }
  // return true;
  // }

  public long getCurrentTimeMillis() {
    return System.currentTimeMillis();
  }

  public int random(int max) {
    return (int) (Math.random() * max);
  }

  public int randomBet(int min, int max) {
    int num = (int) (Math.random() * max);
    if (num < min) {
      num = min;
    }
    return num;
  }

  public String nowFmt(String fmt) {
    return AC.date.fmt(new Date(), fmt);
  }

  public String nowDateTimeStr() {
    return nowFmt("yyyy-MM-dd HH:mm:ss");
  }

  public void sleep(int millis) {
    try {
      Thread.sleep(millis);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }

  public void setPage(Map mp, int num, int size) {
    if (mp != null) {
      mp.put("ac_page_begin", num * size);
      mp.put("ac_page_size", size);
    }
  }

  public boolean openDir(String path) {
    try {
      path = path.replaceAll("//", "/");
      path = path.replaceAll("/", "\\\\");
      // path = path.substring(0, 23);
      Runtime.getRuntime().exec("cmd /c start explorer " + path);
    } catch (IOException e) {
      e.printStackTrace();
    }
    return true;
  }

  public void runCmd(String cmd) {
    try {
      Runtime.getRuntime().exec(cmd);
      // Runtime.getRuntime().exec(new String[]{"cmd", "/c","start chrome
      // http://goo.gl/EsomR0"});
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

  // fileExt
  public String getContentType(String fileExt) {
    if (contentTypeMap == null) {
      contentTypeMap = new HashMap<>();
      Map<String, String> m = contentTypeMap;
      String charSet = ";charset=utf-8";
      m.put("html", "text/html" + charSet);
      m.put("viewer", "text/html" + charSet);
      m.put("css", "text/css" + charSet);
      m.put("styl", "text/css" + charSet);
      m.put("ocss", "text/css" + charSet);
      m.put("js", "text/javascript" + charSet);
      m.put("ajs", "text/javascript" + charSet);
      m.put("vue", "text/javascript" + charSet);
      m.put("jpg", "image/jpeg");
      m.put("gif", "image/gif");
      m.put("bmp", "image/bmp");
      m.put("png", "image/png");
      m.put("jpeg", "image/jpeg");
      m.put("mp3", "audio/mpeg");
      m.put("zip", "application/zip");
      m.put("woff", "application/font-woff");
      m.put("ttf", "application/font-ttf");
      m.put("svg", "image/xml+svg");
    }
    return contentTypeMap.get(fileExt);
  }

  // 获取文件精简名称 /dir1/dir2/123.txt - > 123.txt
  public String getFileSimpleName(String filepath) {
    return FileUtil.getName(filepath);
  }

  public String getClassPath() {
    return AC.system.getClassPath();
  }

  public List<File> getFiles(String path) {
    List<File> lsFiles = new ArrayList<>();
    try {
      File[] ls = FileUtil.ls(path);
      for (File item : ls) {
        lsFiles.add(item);
      }
      return lsFiles;
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    return null;
  }

  public byte[] readFileBytes(String filePath) {
    try {
      return FileUtil.readBytes(filePath);
    } catch (Exception ex) {
      return null;
    }
  }

  public String readFileTxt(String path) {
    return FileUtil.readUtf8String(path);
  }

  public String readFileTxtByFile(File file) {
    return FileUtil.readUtf8String(file);
  }

  public Boolean writeFileTxt(String path, String content) {
    try {
      FileUtil.writeUtf8String(content, path);
    } catch (Exception ex) {
      return false;
    }
    return true;
  }

  public String uuid() {
    return AC.system.getUUid();
  }

  // classpath
  public String getPath(String root, String defaultPath) {
    if (AC.isEmpty(root)) {
      if (defaultPath.startsWith("classpath:")) {
        return getClassPath(defaultPath);
      }
      return defaultPath;
    } else if (root.startsWith("classpath:")) {
      root = this.getClassPath(root);
    }
    return getAbsPath(root);
  }

  public String getClassPath(String root) {
    String path = root.substring(10);// , uniIndex).replace("classpath:", "");
    if (path.startsWith("/") || path.startsWith("\\")) {
      path = path.substring(1);
    }
    root = AC.system.getClassPath() + path;
    return root;
  }

  public String getFileExt(String filePath) {
    return AC.file.extName(filePath);
  }

  public String getAbsPath(String path) {
    if (path.contains("../")) {
      path = path.replaceAll("\\\\", "/");
      String[] sp = path.split("/");
      List<String> ls = new LinkedList<>();
      for (String str : sp) {
        if ("..".equals(str)) {
          if (!AC.empty(ls)) {
            ls.remove(ls.size() - 1);
          }
        } else {
          ls.add(str);
        }
      }
      String newPath = null;
      for (String str : ls) {
        if (newPath == null) {
          newPath = str;
        } else {
          newPath += "/" + str;
        }
      }
      return newPath;
    }
    return path;
  }

  public String enter(String str) {
    return "\n" + str;
  }

  public String quote(String str) {
    return "'" + str + "'";
  }

  public String nowDateStr() {
    return AC.date.fmtDate(new Date());
  }

  public static boolean regularTest(String str, String reg) {
    if (str == null)
      return false;
    return str.matches(reg);
  }

  /**
   * 生成订单号（25位）：时间（精确到毫秒）+5位用户id+3位随机数
   */
  public static synchronized String getOrderNum(Integer userId) {
    // 时间（精确到毫秒）
    DateTimeFormatter ofPattern = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");
    String localDate = LocalDateTime.now().format(ofPattern);
    // 3位随机数
    String randomNumeric = RandomStringUtils.randomNumeric(3);
    String str = "";
    if (userId > 0) {
      // 5位用户id
      int subStrLength = 5;
      String sUserId = userId.toString();
      int length = sUserId.length();
      if (length >= subStrLength) {
        str = sUserId.substring(length - subStrLength, length);
      } else {
        str = String.format("%0" + subStrLength + "d", userId);
      }
    }
    String orderNum = localDate + str + randomNumeric;
    return orderNum;
  }

  public static Map getSyscInfo() {
    Map mp = new HashMap<>();
    OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
    double cpuLoad = osmxb.getSystemCpuLoad();
    int percentCpuLoad = (int) (cpuLoad * 100);
    // 获取内存
    double totalvirtualMemory = osmxb.getTotalPhysicalMemorySize();
    double freePhysicalMemorySize = osmxb.getFreePhysicalMemorySize();
    mp.put("cpuPercent", percentCpuLoad);
    mp.put("memorySum", (int) (totalvirtualMemory / 1024 / 1024));
    mp.put("memoryFree", (int) (freePhysicalMemorySize / 1024 / 1024));
    return mp;
  }

  public Date nowDate() {
    return new Date();
  }

  /**
   * 生成订单号（19位）：时间（精确到毫秒 13）+3位用户id+3位随机数
   */
  public static synchronized String getOrderNum19(Integer userId) {

    // 时间（精确到毫秒）
    DateTimeFormatter ofPattern = DateTimeFormatter.ofPattern("HHmmssSSS");
    LocalDateTime now = LocalDateTime.now();
    int year = now.getYear();
    int day = now.getDayOfYear();
    String dayStr = "";
    if (day < 100) {
      dayStr += "0";
    }
    if (day < 10) {
      dayStr += "0";
    }
    dayStr += day;
    String localDate = now.format(ofPattern);
    // 3位随机数
    String randomNumeric = RandomStringUtils.randomNumeric(3);
    String str = "";
    if (userId > 0) {
      // 5位用户id
      int subStrLength = 3;
      String sUserId = userId.toString();
      int length = sUserId.length();
      if (length >= subStrLength) {
        str = sUserId.substring(length - subStrLength, length);
      } else {
        str = String.format("%0" + subStrLength + "d", userId);
      }
    }
    String orderNum = (year - 2022) + dayStr + localDate + str + randomNumeric;
    return orderNum;
  }

  public int compareToday(Date dt) {
    if (dt == null) {
      return 0;
    }
    int len = 0;
    Date now = new Date();
    long millies = now.getTime() - dt.getTime();
    len = (int) (millies / (1000 * 60 * 60 * 24));
    return len;
  }

  public Date getDate(String v) {
    return AC.date.parseAuto(v);
  }

  public Date getDateFmt(String v, String fmt) {
    return AC.date.parse(v, fmt);
  }

  // 2023-11-09T13:10:50
  public Date getDateYmdTHsm(String v) {
    try {
      return sdfYmdTHms.parse(v);
    } catch (Exception ex) {
      ex.printStackTrace();
      return null;
    }
  }

  // 获取系统类型 windows linux harmoney
  public String getOsType() {
    if (osType != null) {
      return osType;
    }
    osType = System.getProperty("os.name");
    osType = osType.toLowerCase();
    if (osType.indexOf("linux") >= 0) {
      osType = "linux";
    } else if (osType.indexOf("windows") >= 0) {
      osType = "windows";
    }
    return osType;
  }

  public String exec(String cmdStr) {
    return RuntimeUtil.execForStr(cmdStr);
  }

  public boolean fileExists(String fullPath) {
    return FileUtil.exist(fullPath);
  }
}
